<template>
  <div class="box">
    <el-form label-width="100px" :inline="true">
      <el-row>
        <el-form-item label="基站名称：">
          <el-input
            v-model.trim="search.baseStationName"
            @keyup.enter.native="onSubmit"
            placeholder="请输入"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="SN码：">
          <el-input
            v-model.trim="search.baseStationSN"
            @keyup.enter.native="onSubmit"
            placeholder="请输入"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit" size="small"
            >搜索</el-button
          >
          <el-button type="primary" @click="onReset" size="small"
            >重置</el-button
          >
        </el-form-item>
      </el-row>
    </el-form>
    <nice-table
      :data="list"
      :columns="columns"
      :pagination="pagination"
      class="margin-top20"
    >
      <el-table-column
        label="操作"
        align="center"
        width="100"
        slot="opreation"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button size="small" type="text" @click="onView(scope.row)"
            >查看</el-button
          >
          <el-button size="small" type="text" @click="onEdit(scope.row)"
            >编辑</el-button
          >
          <el-button size="small" type="text" @click="onEdit(scope.row)"
            >绑定班级</el-button
          >
          <el-button size="small" type="text" @click="onDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </nice-table>
  </div>
</template>
<script>
import base from '@/views/base.vue';
import { cascadeQuery } from '@/api/api.js';
export default {
  name: 'base-station',
  extends: base,
  data() {
    return {
      search: {
        baseStationName: '', // 基站名称
        baseStationSN: '', // SN码
      },
      pagination: {
        total: 0,
        pageNum: 1,
        pageSize: 10,
        handleCurrentChange: this.handleCurrentChange,
        handleSizeChange: this.handleSizeChange,
      },
      list: [],
      loading: false,
      columns: [
        {
          label: '序号',
          prop: 'order',
        },
        {
          label: '基站名称',
          prop: 'baseStationName',
        },
        {
          label: '简介',
          prop: 'baseStationDetail',
        },
        {
          label: 'SN码',
          prop: 'baseStationSN',
        },
        {
          label: '配对答题器数量',
          prop: 'baseStationNumber',
        },
      ],
    };
  },
  activated() {
    this.getDataList();
  },
  methods: {
    async getDataList() {
      // todo 待联调
      let res = await cascadeQuery({
        table_name: 'nice_course_comment',
        condition: {
          course_id: this.search.course_id,
          course_period_id: this.search.course_period_id,
          course_lesson_id: this.search.course_lesson_id,
        },
        by_page: {
          currPage: this.pagination.pageNum,
          pageSize: this.pagination.pageSize,
        },
      });
      if (res[0]) {
        return;
      }
      let data = res[1];
      if (data && data.code === 0) {
        this.pagination.total = data.data.totalCount;
        this.list = data.data.list;
      }
    },
    onSubmit() {
      this.pagination.pageNum = 1;
      this.getDataList();
    },
    onReset() {
      // todo
      this.search = this.$options.data().search;
      this.pagination.pageNum = 1;
      this.getDataList();
    },
    onChange() {
      this.getDataList();
    },
    handleCurrentChange(val) {
      this.pagination.pageNum = val;
      this.getDataList();
    },
    handleSizeChange(val) {
      this.pagination.pageSize = val;
      this.getDataList();
    },
    onView(row) {
      this.$router.push({
        name: 'base-station-detail',
        params: { id: row.id },
      });
    },
    onEdit() {
      // todo
    },
    onDelete() {
      // todo
    },
  },
};
</script>
<style lang="scss" scoped></style>
